﻿using Student.Common;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Student.Model
{
    public class PagedList<T>
    {
        [JsonProperty("currentPage")]
        public int CurrentPage { get; set; }

        [JsonProperty("pageSize")]
        public int PageSize { get; set; }

        [JsonProperty("total")]
        public int Total { get; set; }

        [JsonProperty("totalPageCount")]
        public int TotalPageCount { get; set; }

        [JsonProperty("hasPrevPage")]
        public bool HasPrevPage { get; set; }

        [JsonProperty("hasNextPage")]
        public bool HasNextPage { get; set; }

        [JsonProperty("list")]
        public List<T> List { get; set; }

        public PagedList(List<T> list, int pageIndex, int pageSize, int totalCount, dynamic? flag = null)
        {
            if (totalCount > 0)
            {
                CurrentPage = pageIndex + 1;
            }
            else
            {
                CurrentPage = 0;
            }
            PageSize = pageSize;
            Total = totalCount;
            TotalPageCount = ConvertHelper.ToInt(Math.Ceiling((double)totalCount / pageSize));
            HasPrevPage = CurrentPage > 1;
            HasNextPage = CurrentPage < TotalPageCount;
            List = list;
        }
    }

    public class ListViewModel<T>
    {
        [JsonProperty("list")]
        public List<T> List
        {
            get; set;
        } = new List<T>();

        [JsonProperty("total")]
        public int Total
        {
            get; set;
        }
    }
}